<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
<body>
<%
	session.invalidate();
%>
<div class="htmleaf-container">
	<div id="wrapper" class="login-page">
	  <div id="login_form" class="form">
		<form class="register-form" name="g" onsubmit="return check_register(this);">
		  <input type="text" placeholder="用户名" name="shopName" id="r_user_name"/>
		  <input type="text" placeholder="用户电话" name="shopTel" id="r_user_tel" />
		  <input type="password" placeholder="密码" name="shopPass" id="r_password"/>
		  <button id="create">创建账户</button>
		  <p class="message">已经有了一个账户? <a href="#">立刻登录</a></p>
		</form>
		<form class="login-form" name="f" action="${pageContext.request.contextPath }/shopLogin" method="post" onsubmit="return check_login(this);">
		  <input type="text" name="shopTel" placeholder="用户电话" id="user_name"/>
		  <input type="password" name="shopPass" placeholder="密码" id="password"/>
		  <button id="login">登　录</button>
		  <p class="message">还没有账户? <a href="#">立刻创建</a></p>
		</form>
	  </div>
	</div>
</div>
</body>
<script type="text/javascript">
	function check_login()
	{
		 var name=$("#user_name").val();
		 var pass=$("#password").val();
		 if(name=="" && pass=="")
		 {
		  alert("请输入用户名或密码！");
		  $("#user_name").val("");
		  $("#password").val("");
		
		 }
	}
	function check_register(){
		var shopName = g.shopName.value;
		var shopPass = g.shopPass.value;
		var shopTel = g.shopTel.value;
/* 		if(shopName!="" && shopPass=="" && shopTel != "")
		 {
		  alert("注册成功！");
		  $("#user_name").val("");
		  $("#password").val("");
		 }
		 else
		 {
		  $("#login_form").removeClass('shake_effect');  
		  setTimeout(function()
		  {
		   $("#login_form").addClass('shake_effect')
		  },1);  
		 } */
		if(confirm("确认注册？")){
			$.ajax({
				type:"post",//设置提交方式
				url:"${pageContext.request.contextPath}/shopRegist",
				async:true,//表示进行异步执行
				dataType:"json",//数据的返回类型
				data:{
					shopName:shopName,
					shopPass:shopPass,
					shopTel:shopTel
					},
				success:function(data){//data就是成功之后 Servlet返回的结果
					if(data == 9){
						alert("用户已存在！");
					}else if(data == 1){
						alert("注册成功！");
						
					}else{
						alert("注册失败！")
					}
				},
				error:function(err){
					alert("操作失败");
				}
			});
		}
	}
	$(function(){
/* 		$("#create").click(function(){
			check_register();
			return false;
		})
		$("#login").click(function(){
			check_login();
			return false;
		}) */
		$('.message a').click(function () {
			$('form').animate({
				height: 'toggle',
				opacity: 'toggle'
			}, 'slow');
		});
	})
</script>
</html>